package com.kili.mirco.spark_als.web;

import com.kili.mirco.spark_als.model.Ratings;
import com.kili.mirco.spark_als.ref.delegate.MFMDelegator;
import com.kili.mirco.spark_als.ref.hanlder.RecommendProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

import static com.kili.mirco.spark_als.com.ModuleType.MFM;

/**
 * @date 19-6-4
 * @auther jackliang
 * @description TODO
 */
@RestController
@RequestMapping("/v1/matrix")
public class MatrixAlsController {

    @Autowired
    private MFMDelegator delegator;


    /**
     * @param itemId
     * @return
     */
    @GetMapping("/similarity/item/sink/{itemId}")
    public ResponseEntity<List<Ratings>> secureSimilarityItemOfItemId(@PathVariable Long itemId) {
        return ResponseEntity.ok(delegator.mfm_delegator.refiningSimilarityItemCF(itemId));
    }

    /**
     * @param userId
     * @param nums
     * @return
     */
    @GetMapping("/similarity/recommend/item/user-{userId}/{nums}")
    public ResponseEntity<List<Ratings>> secureSimilarityNumItemsOfOneUser(@PathVariable Integer userId, @PathVariable Integer nums) {
        return ResponseEntity.ok(delegator.mfm_delegator.recommendProducts(userId, nums));
    }

    /**
     * @param nums
     * @return
     */
    @GetMapping("/similarity/recommend/{nums}-users/all/product")
    public ResponseEntity<Map<Integer, List<Ratings>>> secureSimilarityItemsOfAllUser(@PathVariable Integer nums) {
        return ResponseEntity.ok(delegator.mfm_delegator.recommendUsersForProducts(nums));
    }


    /**
     * @param itemId
     * @param nums
     * @return
     */
    @GetMapping("/similarity/recommend/user/user-{itemId}/{nums}")
    public ResponseEntity<List<Ratings>> secureSimilarityNumUsersOfOneItem(@PathVariable Integer itemId, @PathVariable Integer nums) {
        return ResponseEntity.ok(delegator.mfm_delegator.recommendUsers(itemId, nums));
    }


    /**
     * @param nums
     * @return
     */
    @GetMapping("/similarity/recommend/{nums}-items/all/users")
    public ResponseEntity<Map<Integer, List<Ratings>>> secureSimilarityUsersOfAllitem(@PathVariable Integer nums) {
        return ResponseEntity.ok(delegator.mfm_delegator.recommendProductsForUsers(nums));
    }
}
